import javax.swing.*;

/**
 * MyQueue class.
 * Used to simulate the lines in a store.
 * @author Martin
 *
 */
public class MyQueue {
	//	Local variables	
	private DefaultListModel _inLineList;
	private Boolean _isOpen;
	
	/**
	 * Constructor
	 */
	public MyQueue(){
		_inLineList = new DefaultListModel();
		_isOpen = false;
	}
	
	/**
	 * Adds a person to the line.
	 * Pre: The line must be open , _isOpen == true, and a new customer must
	 * have been made;
	 * Post: Adds a person to the back of this line.
	 */
	public void enqueue(Person aPerson)
	{
		_inLineList.addElement(aPerson);
	}
	
	/**
	 * Removes the first person from the line
	 * Pre: The line, _inLineList, may not be empty and the line
	 * may not be closed, !_isOpen == false.
	 * Post: First element in _inLineList is removed.
	 */
	public void dequeue()
	{
		_inLineList.remove(0);
	}
	
	/**
	 * Gets the amount of people in the line.
	 * Pre: true
	 * Post: the number of people in the list.
	 */
	public int getSize()
	{
		return _inLineList.getSize();
	}
	
	/**
	 * Gets the list of customers in the line.
	 * Pre: true
	 * Post: the elements of the list
	 */
	public DefaultListModel getCustomerInLineList() 
	{
		return _inLineList;
	}
	
	/**
	 * Gets the line status, if its open or not.
	 * Pre: a line must have been selected.
	 * Post: true or false depening on status.
	 */
	public Boolean get_isOpen() 
	{	
		return _isOpen;
	}
	
	/**
	 * Gets a person in the line.
	 * Pre: a person and a line must have been selected.
	 * Post: returns the selected person in the selected line.
	 */
	public Person getPerson(int aIndex)
	{
		return (Person)_inLineList.get(aIndex);
	}
	
	/**
	 * Sets if the line is open or not.
	 * Pre: a line must have been selected.
	 * If the amount of lines open == 1, _isOpen cant be set to false.
	 * Post:sets this line _isOpen to true or false; 
	 */
	public void set_isOpen(Boolean isOpen) 
	{
		_isOpen = isOpen;
	}
}
